home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / ungepackte_daten / 1992 / 09 / 2 / programmieren os2.0 / addappwindow.c < prev   
Encoding:
C/C++ Source or Header  |  1995-06-01  |  3.4 KB  |  92 lines

  1. #include <exec/memory.h>
  2. #include <intuition/intuition.h>
  3. #include <workbench/startup.h>
  4. #include <workbench/workbench.h>
  5.  
  6. #ifdef LATTICE
  7. #include <stdio.h>
  8.   int CXBRK(void){ return (0); }
  9.   int chkabort(void){ return (0); }
  10.  
  11.   #include <clib/exec_protos.h>
  12.   #include <clib/intuition_protos.h>
  13.   #include <clib/icon_protos.h>
  14.   #include <clib/wb_protos.h>
  15. #endif
  16.  
  17. struct IntuitionBase *IntuitionBase=NULL;
  18. struct WorkbenchBase *WorkbenchBase=NULL;
  19.  
  20. void main() {
  21.   struct MsgPort *msgport;
  22.   struct Window  *window;
  23.   struct AppWindow *appwindow;
  24.   struct IntuiMessage *imsg;
  25.   struct AppMessage *appmsg;
  26.   struct WBArg   *argptr;
  27.   ULONG  WindowID = 1, UserData = 0;
  28.   BOOL   ABORT = FALSE;
  29.   UBYTE  i;
  30.  
  31.   if( IntuitionBase=OpenLibrary("intuition.library", 37)) {
  32.     if( WorkbenchBase=OpenLibrary("workbench.library", 37)) {
  33.       /*
  34.        * Den benötigten Message-Port erstellen
  35.        */
  36.       if( msgport=CreateMsgPort() ) {
  37.         if( window=OpenWindowTags( NULL, WA_Left,  10,   WA_Top, 10,
  38.                                          WA_Width, 320, WA_Height, 50,
  39.                                          WA_IDCMP, CLOSEWINDOW,
  40.                                          WA_Flags, WINDOWCLOSE | WINDOWDRAG,
  41.                                          WA_Title, "AmigaAppWindow", TAG_END)) {
  42.           /*
  43.            * Hier erfolgt der Eintrag des Fensters als Application-Window
  44.            */
  45.           if( appwindow=AddAppWindow(WindowID, UserData, window, msgport, NULL)) {
  46.             do {
  47.               /*
  48.                * Nun warten wir entweder auf eine IDCMP-Message
  49.                * oder eine AppMessage
  50.                */
  51.               Wait(1 << window->UserPort->mp_SigBit | 1 << msgport->mp_SigBit);
  52.               while( imsg=(struct IntuiMessage *)GetMsg(window->UserPort)) {
  53.                 if( imsg->Class=CLOSEWINDOW )
  54.                   ABORT=TRUE;
  55.                   ReplyMsg((struct Message *) imsg);
  56.               }
  57.               while( appmsg=(struct AppMessage *)GetMsg(msgport)) {
  58.                 /*
  59.                  * Die AppMessage kann nur vom Typ MTYPE_APPWINDOW sein.
  60.                  * ID und userdata sind die von uns vorgegebenen Werte.
  61.                  * Mit NumArgs lassen sich die Workbench-Argumente aus-
  62.                  * lesen.
  63.                  */
  64.                 printf("AppMsg=%lx, Typ=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n",
  65.                               appmsg, appmsg->am_Type, appmsg->am_ID,
  66.                               appmsg->am_UserData, appmsg->am_NumArgs);
  67.  
  68.                 /*
  69.                  * Jetzt die Argumente auswerten
  70.                  */
  71.                 argptr = appmsg->am_ArgList;
  72.                 for(i = 0; i < appmsg->am_NumArgs; i++) {
  73.                    printf("Argument(%ld): Name='%s', Lock=%lx\n",
  74.                                 i, argptr->wa_Name, argptr->wa_Lock);
  75.                    argptr++;
  76.                 }
  77.                 ReplyMsg((struct Message *)appmsg);
  78.               }
  79.             } while (ABORT == FALSE);
  80.             RemoveAppWindow(appwindow);
  81.           } else printf("Das Fenster konnte nicht als AppWindow "
  82.                         "AppWindow deklariert werden\n");
  83.           CloseWindow(window);
  84.         } else printf("Konnte Fenster nicht öffnen\n");
  85.         DeleteMsgPort(msgport);
  86.       } else printf("Konnte Message-Port nicht einrichten\n");
  87.       CloseLibrary(WorkbenchBase);
  88.     } else printf("Konnte workbench.library nicht öffnen\n");
  89.     CloseLibrary(IntuitionBase);
  90.   } else printf("Konnte intuition.library nicht öffnen\n");
  91. }
  92.